package action;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

import network.CmdAnalyserAndHandle;

public class NetworkProcessAction{
	private CmdAnalyserAndHandle clp;
	private DataProcessAction da;
	
	public NetworkProcessAction() throws FileNotFoundException {
		clp = new CmdAnalyserAndHandle();
	}

	public void networkDataProcess() throws Exception {
			ServerSocket server = new ServerSocket(8889);
			Socket socket = server.accept();	
			OutputStream out = socket.getOutputStream();
			InputStream in = socket.getInputStream();
			
			out.write("please enter a commad:\r\n".getBytes());
			BufferedReader reader = new BufferedReader(new InputStreamReader(in));
			
			boolean status = true;
			while(status){
				String cmd = reader.readLine();
				status = clp.cmdAnalyseAndHandle(cmd, out);     //获得命令参数，传入
				out.write("please enter a commad:\r\n".getBytes());
			}
			
			in.close();
			out.close();
			socket.close();
			server.close();
	}
	
	public static void main(String[] args) throws Exception {
		try{
		NetworkProcessAction na = new NetworkProcessAction();
		na.networkDataProcess();
		}
		catch(Exception e){
			e.printStackTrace();
		}
	}
}
